/*******************************************************************
 * 外语翻译平台(translate) 
 *
 * 成都一亿信息技术公司 版权所有
 * 
 * Copyright (C) 2010 Transer Information Technology Co., Ltd.
 *
 * @Version : 1.0  2010-12-25 下午08:10:23
 *
 * AuthCodeInterceptor.java 
 *
 *******************************************************************/
package com.transer.web.interceptor;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
import com.transer.constant.Constants;
import com.transer.persistance.bean.User;
import com.transer.web.exception.NotLoginException;
import com.transer.web.exception.PermissionNotAllow;

/**
 * class defination are there
 * 
 * @author Administrator
 * 
 * @version 1.0 ywengineer@gmail.com
 * 
 */
public class TranserPermissionCheckInterceptor implements Interceptor {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7301292134390669694L;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.opensymphony.xwork2.interceptor.Interceptor#destroy()
	 */
	public void destroy() {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.opensymphony.xwork2.interceptor.Interceptor#init()
	 */
	public void init() {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.opensymphony.xwork2.interceptor.Interceptor#intercept(com.opensymphony
	 * .xwork2.ActionInvocation)
	 */
	public String intercept(ActionInvocation invocation) throws Exception {
		// 查看是否登陆
		User user = (User) ActionContext.getContext().getSession().get(Constants.SESSION_USER);
		// 返回状态
		String result = null;
		// 如果没登陆
		if (user == null) {
			throw new NotLoginException("not login");
		} else if (user.getType() != Constants.USER_TYPE_PUBLISHER) {// 不是发布方,就满足权限
			result = invocation.invoke();
		} else {
			throw new PermissionNotAllow();
		}
		return result;
	}

}
